package com.hntxk.cqzd.export.controller;/**
 * @ClassName: ${user}
 * @Author:liuqing
 * @Description
 * @Date: Created in 20:07 2020/9/21
 * @Modified By:
 */

import com.alibaba.fastjson.JSON;
import com.hntxk.core.framework.action.BaseController;
import com.hntxk.cqzd.export.model.DiagnosisExport;
import com.hntxk.cqzd.export.model.ExcelExportConstant;
import com.hntxk.cqzd.export.model.QueryParamModel;
import com.hntxk.cqzd.export.service.DiagnosisExportsService;
import com.hntxk.cqzd.export.util.ExcelUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @ClassName DiagnosisExportController
 * @description 诊断信息导出web层
 * @Author Liuqing
 * @Date 2020/9/21 20:07
 * @Version 1.0
 */
@Api(value="诊断信息导出", tags={"[SP]诊断信息导出"})
@Controller
@RequestMapping("cqzd/Diagnosis")
@Slf4j
public class DiagnosisExportController extends BaseController {


    private final DiagnosisExportsService service;

    @Autowired
    public DiagnosisExportController(@Qualifier("diagnosisService") DiagnosisExportsService service) {
        super();
        this.service = service;
    }

    @ResponseBody
    @RequestMapping(value = "/selDiagnosisAll",method = RequestMethod.GET)
    public String selDiagnosisAll(@ModelAttribute QueryParamModel model, HttpServletResponse response){
        List<DiagnosisExport> diagnosisExports = service.selDiagnosisAll(model);

        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ExcelUtil.generateExcelSaveLocal(diagnosisExports,
                ExcelExportConstant.DIAGNOSIS_TITLE1,
                ExcelExportConstant.DIAGNOSIS_TITLE2,
                ExcelExportConstant.DIAGNOSIS_MERGED_REGION,
                ExcelExportConstant.DIAGNOSIS_FIELD,
                response,formatter.format(currentTime).replace(" ","-").replace(":","-"));
        return JSON.toJSONString("success");

    }
}
